package com.gamecollection.snake.model.obj;

import com.gamecollection.snake.model.SnakeModel;

import java.awt.*;

/**
 * 游戏对象基类
 */
public class GameObj {
    
    // 图片
    protected Image img;
    // 坐标
    protected int x;
    protected int y;
    // 宽高
    protected int width = 30;
    protected int height = 30;
    // 模型引用
    protected SnakeModel model;
    
    public GameObj() {
    }
    
    public GameObj(Image img, int x, int y, SnakeModel model) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.model = model;
    }
    
    public GameObj(Image img, int x, int y, int width, int height, SnakeModel model) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.model = model;
    }
    
    /**
     * 绘制自身
     */
    public void paintSelf(Graphics g) {
        g.drawImage(img, x, y, null);
    }
    
    /**
     * 更新对象状态
     */
    public void update() {
        // 子类可以重写此方法
    }
    
    // Getter和Setter方法
    public Image getImg() {
        return img;
    }
    
    public void setImg(Image img) {
        this.img = img;
    }
    
    public int getX() {
        return x;
    }
    
    public void setX(int x) {
        this.x = x;
    }
    
    public int getY() {
        return y;
    }
    
    public void setY(int y) {
        this.y = y;
    }
    
    public int getWidth() {
        return width;
    }
    
    public void setWidth(int width) {
        this.width = width;
    }
    
    public int getHeight() {
        return height;
    }
    
    public void setHeight(int height) {
        this.height = height;
    }
    
    public SnakeModel getModel() {
        return model;
    }
    
    public void setModel(SnakeModel model) {
        this.model = model;
    }
} 